import cv2
import matplotlib.pyplot as plt
import numpy as np

img = cv2.imread('D:/python/opencv-processing/laiya.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 二值化（灰度图，阈值，二值化加工方式）
ret, b1 = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
ret, b2 = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
print(ret)

plt.subplot(121)
plt.imshow(b1,cmap='gray')
plt.subplot(122)
plt.imshow(b2,cmap='gray')
# plt.show('off')
plt.show()